﻿using System;
using System.Windows;
using System.Windows.Input;
using IntelligentPharmacy;
using IntelligentPharmacy.Entity;
using IntelligentPharmacy.publicclass;
using IntelligentPharmacy.httprequest;
using System.Collections.Generic;
using SmartForcer.Enum;
using ConsumablesCabinet;

namespace SmartRoom
{
    /// <summary>
    /// LYJLCXWindows.xaml 的交互逻辑
    /// </summary>
    public partial class LYJLCXWindows : Window
    {
        requestService rq = new requestService();
        public LYJLCXWindows()
        {
            InitializeComponent();
        }
        private void date1_ValueChanged(object sender, EventArgs e)
        {
            txt_DT1.Text = date1.Value.ToString("yyyy-MM-dd");
        }

        private void date2_ValueChanged(object sender, EventArgs e)
        {
            txt_DT2.Text = date2.Value.ToString("yyyy-MM-dd");
        }
        /// <summary>
        /// 查询接口
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_Refresh_Click(object sender, RoutedEventArgs e)
        {

            try
            {
                string startDate = txt_DT1.Text;
                string endDate = txt_DT2.Text;
                Querydto qdto = new Querydto();
                qdto.startDate = startDate;

                DateTime endtimes = DateTime.Parse(endDate);
                string sj = endtimes.AddDays(1).ToShortDateString(); ;
                qdto.endDate = sj;

                qdto.userId = Global.User.empId;
                qdto.inStoreroomId = DeviceInfo.GetMacAddress();
                bool ly = (bool)chx_LY.IsChecked;
                bool gh = (bool)chx_GH.IsChecked;
                List<MaterialnformationEntity> list = new List<MaterialnformationEntity>();
                if (ly)
                {
                    qdto.InoutFlag = "0";
                    List<MaterialnformationEntity> lists = rq.getOutPutRecord(qdto);
                    foreach (MaterialnformationEntity item in lists)
                    {
                        item.CZLX = "出库";
                    }
                    list.AddRange(lists);
                }
                if (gh)
                {
                    Querydto qdto1 = new Querydto();
                    qdto1.startDate = startDate;
                    qdto1.endDate = sj;
                    qdto1.userId = Global.User.empId;
                    //qdto.userId = "1307532";
                    qdto1.inStoreroomId = DeviceInfo.GetMacAddress();
                    qdto1.InoutFlag = "1";
                    List<MaterialnformationEntity> lists = rq.getOutPutRecord(qdto1);
                    foreach (MaterialnformationEntity item in lists)
                    {
                        item.CZLX = "入库";
                    }
                    list.AddRange(lists);
                }
                if (!gh && !ly)
                {
                    Global.MessageWindow.ShowDialog("请选择出入库类型");
                    return;
                }
                try
                {
                    list.Sort((e1, e2) => e1.inputDate.CompareTo(e2.inputDate));
                    lvw_DJ.ItemsSource = list;

                }
                catch (Exception ex)
                {
                    Global.MessageWindow.ShowDialog("查询历史单据出现异常！" + ex.Message, MessageButton.Close, MessageStyle.Error);
                    return;
                }
            }catch(Exception ex) { }
        }
        private void btn_Close_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

            chx_LY.IsChecked = chx_GH.IsChecked = true;
         

            txt_DT1.Text = date1.Value.ToString("yyyy-MM-dd");       
            txt_DT2.Text = date2.Value.ToString("yyyy-MM-dd");
        }

        private void lvw_DJ_MouseUp(object sender, MouseButtonEventArgs e)
        {
           
        }
    }
}
